package com.alamiya.security.service.impl;

import com.alamiya.security.entity.PublicAuthority;
import com.alamiya.security.mapper.PublicAuthorityMapper;
import com.alamiya.security.service.IPublicAuthorityService;
import com.alamiya.security.service.IPublicRoleAuthorityRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hehaoqi
 * @since 2021-02-09
 */
@Service
public class PublicAuthorityServiceImpl extends ServiceImpl<PublicAuthorityMapper, PublicAuthority> implements IPublicAuthorityService {

    @Autowired
    IPublicRoleAuthorityRelationService roleAuthorityRelationService;

    @Override
    public List<String> listAuthorityNamesByRoleId(String roleId) {
        List<String> authorityIds = roleAuthorityRelationService.listAuthorityIdsByRoleId(roleId);
        List<String> authorityNames = new ArrayList<>(authorityIds.size());
        for (String authorityId : authorityIds) {
            authorityNames.add(getById(authorityId).getAuthorityName());
        }
        return authorityNames;
    }
}
